﻿//这里的代码，是此控件操作复选择框的，主要作用是当父结点被选择时，子结点根着对应变化
var ignoreEvents = false;
function nodeEventHandler(treeview, node, eventType) {
    if (ignoreEvents) return;
    ignoreEvents = true;
    if (eventType == "checked") {
        setChildrenCheckBox(node, true);

        if (allSiblingChecked(node)) {
            //setParentCheckBox(node, true);
        }
    } else if (eventType == "unchecked") {
        setChildrenCheckBox(node, false);
        //setParentCheckBox(node, false);
    } else if (eventType == "expanded") {
        node.setImageUrl('../images/topo/operation/folder_open.gif');
    } else if (eventType == "collapsed") {
        node.setImageUrl('../images/topo/operation/folder.gif');
    }
    else if (eventType == "selected") {
        //NodeSelected(node);
    }
    ignoreEvents = false;
}
function setChildrenCheckBox(parentNode, value) {
    var childNodes = parentNode.getChildNodes();
    for (var i = 0; i < childNodes.length; i++) {
        var node = childNodes[i];
        node.setChecked(value);
        setChildrenCheckBox(node, value);
    }
}
function setParentCheckBox(node, value) {
    var parentNode = node.getParent();
    if (parentNode == null) return;
    parentNode.setChecked(value);
    if (!value || allSiblingChecked(parentNode))
        setParentCheckBox(parentNode, value);
}
function allSiblingChecked(node) {
    var nodes = node.getSiblingNodes();
    for (var i = 0; i < nodes.length; i++) {
        if (!nodes[i].getChecked())
            return false;
    }
    return true;
}
function NodeSelected(node) {
    var url = 'RoomPlaneRight.aspx?tType=';
    if (node.getAttribute("flag") == "Leve") {
        url += escape(node.getValue());
        // var url="UnitManage.aspx?name="+ escape(newNode.getText())+"&id="+newNode.getValue()+"&key="+newNode.getAttribute("key");
        node.setNavigateTarget("left");
        node.setNavigateUrl(url);
    }
    //       else if(newNode.getAttribute("flag")=="unit")
    //       {
    //          var url="UnitManage.aspx?name="+ escape(newNode.getText())+"&id="+newNode.getValue()+"&key="+newNode.getValue();
    //                newNode.setNavigateTarget("rightFrame");
    //                newNode.setNavigateUrl(url);
    //       }  
}